#!/usr/bin/env bash
# 	./config.status  --file=ff-mpirun:ff-mpirun.in
mpirun=mpirun
dir=`dirname $0`
prefix="@prefix@"
exec_prefix="@exec_prefix@"
bindir="@bindir@"
nw=1
if [ -n "@MPIRUN@"  ] ;then 
case "@MPIRUN@" in
[A-Z]:*) mpirun="@MPIRUN@"  ;;
*) eval mpirun="@MPIRUN@"  ;; 
esac
fi
if [ -n "@MPI_RUN_OPTION@"  ] ;then mpi_run_option="@MPI_RUN_OPTION@"  ; fi	
ffmpi=FreeFem++-mpi
if [ -x "$0" -a -x "$dir/$ffmpi" ]; then 
 if [ -n "@WIN32DLLTARGET@" -a -x "$dir/../bin-win32/$ffmpi.exe" ] ; then 
   ffmpi="$dir/../bin-win32/$ffmpi.exe";
 else 
   ffmpi="$dir/$ffmpi";
 fi    
fi
if [ -d "$bindir" ]  ;then export PATH="@bindir@:$PATH"  ; fi
a[0]="'$mpirun'"
j=1;
test -n "$mpi_run_option" && a[((j++))]="$mpi_run_option"
#echo $1 ---
while test -n "$1" ; do
((j++))

case "$1" in
"-nw") nw=1;;
"-win") nw=0;;
*.edp|*.md) a[$j]="${ffmpi}";
if [ "$nw" -eq 1 ]; then ((j=$j+1));a[$j]="-nw"; fi
((j++));a[$j]="'$1'";;
#if[ ! -f "$1" ]; then echo error file no found "$1"; dry=2; fi;;
-dry) dry=1;; 
*)  a[$j]="$1";;
esac
shift
done
echo "${a[*]}"
if [ -n "$dry" ]; then echo which $ffmpi : `which  "$ffmpi"`; fi
if [ -z "$dry" ]; then eval  "${a[*]}"; fi
